<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>

<body>
    <input type="text" oninput="change()" />
    <script>
        let timer = null;
        let isNext = true;
        let change = () => {
            // clearTimeout(timer);
            // timer = setTimeout(() => {
            //     console.log(111);
            // }, 500);
            //防抖的代码

            if (isNext == false) {
                return;
            }
            isNext = false;
            setTimeout(() => {
                console.log(111);
                isNext = true;
            }, 1000);
            //节流 每过一秒钟就触发一次 每过一秒钟就触发一次
        };

        // 防抖适合用在 表单提交或者表单搜索的场景
        // 节流适合用在滚动条滚动事件
    </script>
</body>

</html>